#pragma once

#include "RoomIncludes.h"

namespace RoomFW {

//
// Class:	PortIndex
//
// Description:	Primary and replication index of a port.  The primary index
//				identifies the equivalent of the port on a diagram.  The
//				replication index basically identifies a binding to that port.
//
// Author:	Andrew Sage
//
class PortIndex
{
public:

	//
	// Use these for primary and replication index types.
	//
	typedef size_t PrimaryIndex;
	typedef size_t ReplicationIndex;

	//
	// Primary port index used to indicate an invalid port index.
	//
	static const PrimaryIndex INVALID = UINT32_MAX;

	//
	// Replication index to use for broadcasts.  Also a flag to indicate
	// that only the primary index has be specified.
	//
	static const ReplicationIndex REPLICATION_BROADCAST = UINT32_MAX;

	//
	// Method:	PortIndex
	//
	// Description:	Constructor.
	//
	// Parameters:	None.
	//
	PortIndex(void);

	//
	// Method:	PortIndex
	//
	// Description:	Constructor.
	//
	// Parameters:
	//
	//	port - Primary index.
	//
	//	replication - Replication index.
	//
	PortIndex(PrimaryIndex port, ReplicationIndex replication = REPLICATION_BROADCAST);

	//
	// Method:	port
	//
	// Description:	Get the primary index.
	//
	// Parameters:	None.
	//
	// Return:	Primary index.
	//
	PrimaryIndex port(void) const;

	//
	// Method:	port
	//
	// Description:	Set the primary index.
	//
	// Parameters:
	//
	//	port - New primary index.
	//
	// Return:	None.
	//
	void port(PrimaryIndex _port);

	//
	// Method:	port
	//
	// Description:	Get the replication index.
	//
	// Parameters:	None.
	//
	// Return:	Replication index.
	//
	ReplicationIndex replication(void) const;

	//
	// Method:	port
	//
	// Description:	Set the replication index.
	//
	// Parameters:
	//
	//	port - New replication index.
	//
	// Return:	None.
	//
	void replication(ReplicationIndex _replication);

	//
	// Method:	operator<
	//
	// Description:	Return true if this is less than specified port index.
	//
	// Parameters:	None.
	//
	//	port - New replication index.
	//
	// Return:	True if this is less than specified port index.
	//
	bool operator<(const PortIndex& rhs) const;

	//
	// Method:	operator==
	//
	// Description:	Return true if this is equal to specified port index.
	//
	// Parameters:	None.
	//
	//	port - New replication index.
	//
	// Return:	True if this is equal to specified port index.
	//
	bool operator == (const PortIndex& rhs) const;

	//
	// Method:	operator==
	//
	// Description:	Return true if this is not equal to specified port index.
	//
	// Parameters:	None.
	//
	//	port - New replication index.
	//
	// Return:	True if this is not equal to specified port index.
	//
	bool operator != (const PortIndex& rhs) const;

	//
	// Serialization.  See Boost documentation.
	//
	virtual void serialize(::boost::archive::binary_oarchive& ar, const unsigned int /*version*/) const;
	virtual void serialize(::boost::archive::binary_iarchive& ar, const unsigned int /*version*/);

private:

	//
	// Primary and Replication index.  Pair.first and Pair.second respectively.
	//
	std::pair<PrimaryIndex, ReplicationIndex> index_;
};

}

